import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:flutter/services.dart';

class QRCodeGeneratePage extends StatefulWidget {
  final String data;
  final String coinType;

  QRCodeGeneratePage(
      {this.data = 'https://www.baidu.com', this.coinType = 'USDT'});

  @override
  _QRCodeGeneratePageState createState() => _QRCodeGeneratePageState();
}

class _QRCodeGeneratePageState extends State<QRCodeGeneratePage>
    with SingleTickerProviderStateMixin {
  AnimationController controller;
  Animation<double> animation;
  Animation<Color> animation1;

  @override
  void initState() {
    super.initState();
    controller =
        AnimationController(vsync: this, duration: Duration(milliseconds: 300));
    animation = Tween(begin: 700.0, end: 200.0).animate(controller);
    animation1 =
        ColorTween(begin: Colors.white, end: Colors.black).animate(controller);
    controller.forward();
    controller.addListener(() {
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      color: animation1.value,
      child: Stack(
        alignment: Alignment.center,
        children: [
          Positioned(top: animation.value, child: QRCodeCard()),
          Positioned(
            top: 15,
            child: SafeArea(
              child: IconButton(
                  color: Colors.red,
                  onPressed: () {
                    Navigator.of(context).pop();
                    // controller.forward();
                  },
                  icon: Icon(Icons.keyboard_arrow_up_sharp,
                      size: 60, color: Colors.grey[700])),
            ),
          )
        ],
      ),
    );
  }
}

class QRCodeCard extends StatelessWidget {
  final String data;
  final String coinType;

  QRCodeCard({this.data = 'https://www.baidu.com', this.coinType = 'USDT'});

  @override
  Widget build(BuildContext context) {
    return Card(
      color: Colors.white,
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(12.0))),
      child: Container(
        width: 310,
        padding: EdgeInsets.symmetric(horizontal: 30, vertical: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
                padding: EdgeInsets.only(bottom: 15),
                child: Text('$coinType地址',
                    style: TextStyle(color: Colors.deepPurple, fontSize: 20))),
            Text('长按保存二维码', style: TextStyle(color: Colors.orange)),
            Container(
                padding: EdgeInsets.symmetric(vertical: 10),
                child: QrImage(data: data, size: 250)),
            Container(
                child: Text(data, maxLines: 2),
                alignment: Alignment.centerLeft),
            Container(
              margin: EdgeInsets.symmetric(vertical: 15),
              width: 250,
              height: 45,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(45))),
              child: RaisedButton(
                color: Colors.orange[300],
                onPressed: () {
                  Clipboard.setData(ClipboardData(text: data));
                  // Clipboard.getData(Clipboard.kTextPlain).then((value) => {print(value.text)});
                },
                child: Text('复制地址', style: TextStyle(color: Colors.white)),
              ),
            ),
            Text('此地址只接受$coinType', style: TextStyle(color: Colors.red)),
            Text('发送其他币种到此地址将无法找回', style: TextStyle(color: Colors.red)),
          ],
        ),
      ),
    );
  }
}
